package com.lagou.order.dao;

import com.lagou.order.pojo.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author stevejson
 */
public interface OrderDao extends JpaRepository<Order, Integer> {

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "update t_order set version=version+1, state= :state where version= :version and `id` = :id")
    Integer updateOrderState(@Param("version") Integer version, @Param("id")Integer id, @Param("state")Integer state);

    Order findFirstByOrderId(Integer id);

}
